#!/usr/bin/env python3
"""
重新创建数据库表
"""
import os
import sys
from flask import Flask
from flask_sqlalchemy import SQLAlchemy

# 添加当前目录到Python路径
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

# 创建Flask应用
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///mama_assist.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

# 初始化数据库
db = SQLAlchemy()
db.init_app(app)

# 导入模型
from models import *

def recreate_tables():
    """重新创建所有表"""
    with app.app_context():
        # 删除所有表
        db.drop_all()
        print("已删除所有表")
        
        # 创建所有表
        db.create_all()
        print("已创建所有表")
        
        print("Tables recreated successfully")

if __name__ == '__main__':
    recreate_tables()